import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class SliderDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => SliderState();
}

class SliderState extends State<SliderDemo> {
  double _value = 0;
  int _dollars = 20;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Slider'),
        centerTitle: true,
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Slider(
            value: _value,
            //最小值
            min: 0,
            //最大值
            max: 100,
            //变化时回调
            onChanged: (newvalue) {
              setState(() {
                _value = newvalue;
              });
            },
            //滑动开始时回调一次
            onChangeStart: (startvalue) {
              print('onChangeStart:$startvalue');
            },
            //滑动结束时回调一次
            onChangeEnd: (endvalue) {
              print('onChangeEnd:$endvalue');
            },
            //分为几块，比如设置为5，Slider只能滑动到5个位置
            divisions: 5,
            //divisions设置显示在节点上的label
            label:'$_value',
            //滑动过的区域的颜色
            activeColor:Colors.blue,
            //未 滑动过的区域的颜色
            inactiveColor: Colors.grey[300],
            semanticFormatterCallback: (newValue){
              return '${newValue.round()} dollars';
            },
          )
        ],
      ),
    );
  }
}
